﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LogoScriptIDE
{
    /// <summary>
    /// Interaction logic for InputboxWindow.xaml
    /// </summary>
    public partial class InputboxWindow : Window
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public InputboxWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 获取输入的数字
        /// </summary>
        /// <returns>用户输入的数字</returns>
        public double getNum()
        {
            return inputNum;
        }

        /// <summary>
        /// 获取输入的字符串
        /// </summary>
        /// <returns>用户输入的字符串</returns>
        public string getString()
        {
            return inputString;
        }

        /// <summary>
        /// 获取输入的状态
        /// </summary>
        /// <returns>当前的输入状态</returns>
        public int inputStatus()
        {
            return inputDone;
        }

        /// <summary>
        /// 用户输入完成的回调函数
        /// </summary>
        private void ui_inputDone_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if ((bool)ui_number.IsChecked)  // 若用户希望输入数字则以double形式存储
                {
                    inputNum = Double.Parse(Convert.ToString(ui_inputText.Text));
                    inputDone = 1;
                }
                else // 若用户希望输入字符串则以string形式存储
                {
                    inputString = ui_inputText.Text; 
                    inputDone = 2;
                }
            }
            catch
            {
                inputDone = -1;
            }
            Hide();
        }
        /// <summary>
        /// 窗口关闭回调函数
        /// 隐藏窗口并取消关闭
        /// </summary>
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            inputDone = 0; // 若不是点击done完毕窗口，则表示没有用户不希望取消了输入数据
            Hide();
            e.Cancel = true;
        }
        /// <summary>
        /// 存储用户输入的数值
        /// </summary>
        private double inputNum;

        /// <summary>
        /// 存储用户输入的字符串
        /// </summary>
        private string inputString;

        /// <summary>
        /// 表示输入的状态
        /// </summary>
        private int inputDone; // -1: something wrong   0: not done     1: done

        /// <summary>
        /// 窗口载入完成回调函数
        /// </summary>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            inputDone = 0;
            inputNum = 0;
            ui_number.IsChecked = true;
        }

        /// <summary>
        /// 取消按钮回调函数
        /// </summary>
        private void ui_inputCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
